#include "internship_com_Sound.h"
#include "Wave.h"

JNIEXPORT jint JNICALL
Java_internship_com_Sound_PlayWaveSound(JNIEnv* env, jobject obj, jstring WaveFile)
{	
	const char* FilePlay = env->GetStringUTFChars(WaveFile, NULL);
	InitializeOpenAL();
	Wave *wav = new Wave();

	// Load Wave file into OpenAL buffer
	wav->Load(FilePlay);
	
	wav->Play();
	
	int	sourceState = AL_PLAYING;
	do {
		alGetSourcei(wav->uiSource, AL_SOURCE_STATE, &sourceState);
	} while(sourceState == AL_PLAYING);
	
	wav->DelWave();
	ShutdownOpenAL();
	
	return 0;
}